package com.rongke.service.impl;

import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.rongke.alipayUtil.alipay.util.AlipayRefundUtil;
import com.rongke.enums.*;
import com.rongke.mapper.AccountMapper;
import com.rongke.mapper.MuserMapper;
import com.rongke.mapper.OrderGoodsMapper;
import com.rongke.mapper.OrdersMapper;
import com.rongke.model.*;
import com.rongke.service.*;
import com.rongke.wxPayUtil.wxRefundUtil.wechat.RefundUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * @OrdersServiceImpl
 * @订单ServiceImpl
 * @version : Ver 1.0
 */
@Service
public class OrdersServiceImpl extends ServiceImpl<OrdersMapper, Orders> implements OrdersService {

    @Autowired
    private OrdersMapper ordersMapper;
    @Autowired
    private SkuService skuService;
    @Autowired
    private MuserMapper muserMapper;
    @Autowired
    private OrdersService ordersService;
    @Autowired
    private MuserService muserService;
    @Autowired
    private OrderGoodsMapper orderGoodsMapper;
    @Autowired
    private AccountService accountService;
    @Autowired
    private OrderGoodsService orderGoodsService;
    @Autowired
    private AccountMapper accountMapper;
    @Autowired
    private FlowDetailService flowDetailService;
    @Autowired
    private OrdersService orderService;
    @Autowired
    private SystemParmService systemParmService;
    @Autowired
    private ExperienceGoodsService experienceGoodsService;
    @Autowired
    private PanicBuyingGoodsService panicBuyingGoodsService;

    @Autowired
    private MsgUserService msgUserService;
    @Autowired
    private MessageService messageService;

    /**
     * @根据条件查找订单
     * @param orders
     * @return
     */
    @Override
    public List<Orders> selectByCondition(Orders orders) {
        return ordersMapper.selectByCondition(orders);
    }
    /**
     *  订单支付
     * @param orderId 订单id
     * @return
     */
    @Override
    public JSONObject OrdersPay(Long orderId,Integer payWay) {
        JSONObject json=new JSONObject();
        Orders orders=ordersMapper.selectById(orderId);
        //获取订单返现哆币总额和雅币总额
        JSONObject jsonObject=orderGoodsService.findCashBackYbAndDuoBi(orderId,orders.getMuserId());
        if("500".equals(jsonObject.getString("code"))){
            json.put("code","500");
            json.put("message",jsonObject.get("message"));
            return json;
        }
        String totalReurnRate=jsonObject.getString("totalReurnRate");
        String totalReturnRatey=jsonObject.getString("totalReturnRatey");
        Muser muser=muserMapper.selectById(orders.getMuserId());
        Account acc=new Account();
        acc.setMuserId(orders.getMuserId());
        Account account=accountMapper.selectOne(acc);
        BigDecimal totalMoney=orders.getTotalPrice();
        BigDecimal unavailableYabi=account.getUnavailableYabi();//不可用余额（雅币）
        BigDecimal unavailableDuobi=account.getUnavailableDuobi();//不可用余额（哆币）
        if(muser.getMemberType()==1){
            if(muser.getNums()<=10){
                muser.setNums(muser.getNums()+1);
                muserMapper.updateById(muser);
                orders.setReturnDuobi(new BigDecimal(totalReurnRate));
                orders.setReturnYabi(new BigDecimal(totalReturnRatey));
            }else {
                orders.setReturnDuobi(new BigDecimal(0));
                orders.setReturnYabi(new BigDecimal(0));
            }

        }else {
            orders.setReturnDuobi(new BigDecimal(totalReurnRate));
            orders.setReturnYabi(new BigDecimal(totalReturnRatey));
        }
        ordersMapper.updateById(orders);
        String title="";
        if(PayTypeEnum.DUOBI.getType()==payWay){
            if(totalMoney.compareTo(account.getDuoBi())>0){
                json.put("code","500");
                json.put("message","账户余额不足");
                return json;
            }else{
                account.setDuoBi(account.getDuoBi().subtract(totalMoney));
            }
            if(muser.getMemberType()==1 && muser.getNums()<=10){
                account.setUnavailableDuobi(unavailableDuobi.add(new BigDecimal(totalReurnRate)));
            }else  if(muser.getMemberType()==2){
                account.setUnavailableDuobi(unavailableDuobi.add(new BigDecimal(totalReurnRate)));
                account.setUnavailableYabi(unavailableYabi.add(new BigDecimal(totalReturnRatey)));
            }
            account.setTotalMoney(account.getTotalMoney().add(totalMoney));
            title="订单支付(哆币支付)";
            //**********************流水记录**********************//
            FlowDetail fd=new FlowDetail();
            fd.setMuserId(orders.getMuserId());
            fd.setFlowType(FlowTypeEnum.ORDER.getType());
            fd.setMoney(totalMoney.multiply(new BigDecimal("-1")));
            fd.setPayType(payWay);
            fd.setTitle(title);
            fd.setGmtDatetime(new Date());
            fd.setOrderNumber(orders.getOrderNumber());
            flowDetailService.insert(fd);
            //*******************返现记录***********************//
            insertFlowDetail(muser.getId(),orderId,totalReurnRate,totalReturnRatey,true);

        }else if(PayTypeEnum.YABI.getType()==payWay){
            if(totalMoney.compareTo(account.getYaBi())>0){
                json.put("code","500");
                json.put("message","账户余额不足");
                return json;
            }else{
                account.setYaBi(account.getYaBi().subtract(totalMoney));
            }
            title="订单支付(雅币支付)";
            //**********************流水记录**********************//
            FlowDetail fd=new FlowDetail();
            fd.setMuserId(orders.getMuserId());
            fd.setFlowType(FlowTypeEnum.ORDER.getType());
            fd.setMoney(totalMoney.multiply(new BigDecimal("-1")));
            fd.setPayType(payWay);
            fd.setTitle(title);
            fd.setGmtDatetime(new Date());
            fd.setOrderNumber(orders.getOrderNumber());
            flowDetailService.insert(fd);
        }else if(PayTypeEnum.ZHIFUBAO.getType()==payWay){
            if(muser.getMemberType()==1 && muser.getNums()<=10){
                account.setUnavailableDuobi(unavailableDuobi.add(new BigDecimal(totalReurnRate)));
            }else  if(muser.getMemberType()==2){
                account.setUnavailableDuobi(unavailableDuobi.add(new BigDecimal(totalReurnRate)));
                account.setUnavailableYabi(unavailableYabi.add(new BigDecimal(totalReturnRatey)));
            }
            account.setTotalMoney(account.getTotalMoney().add(totalMoney));
            if(orders.getAllowPayType()==1){//如果支持哆币支付 账号余额小于应支付金额的话先扣除余额
//                if(account.getDuoBi().compareTo(orders.getTotalPrice())<0 && account.getDuoBi().compareTo(new BigDecimal(0))>0){
//                    //*********流水记录*********//
//                    FlowDetail duobi=new FlowDetail();
//                    duobi.setMuserId(orders.getMuserId());
//                    duobi.setFlowType(FlowTypeEnum.ORDER.getType());
//                    duobi.setMoney(account.getDuoBi().multiply(new BigDecimal("-1")));
//                    duobi.setPayType(PayTypeEnum.DUOBI.getType());
//                    duobi.setTitle("订单支付(哆币抵消金额"+account.getDuoBi()+"哆币)");
//                    duobi.setGmtDatetime(new Date());
//                    duobi.setOrderNumber(orders.getOrderNumber());
//                    flowDetailService.insert(duobi);
//
//
//                    account.setDuoBi(new BigDecimal(0));
//                }
            }else if(orders.getAllowPayType()==2){//如果支持雅币支付 账号余额小于应支付金额的话先扣除余额
                if(account.getYaBi().compareTo(orders.getTotalPrice())<0 && account.getYaBi().compareTo(new BigDecimal(0))>0){
                    //*********流水记录*********//
                    FlowDetail yabi=new FlowDetail();
                    yabi.setMuserId(orders.getMuserId());
                    yabi.setFlowType(FlowTypeEnum.ORDER.getType());
                    yabi.setMoney(account.getYaBi().multiply(new BigDecimal("-1")));
                    yabi.setPayType(PayTypeEnum.YABI.getType());
                    yabi.setStatus(1);
                    yabi.setTitle("订单支付(雅币抵消金额"+account.getYaBi()+"雅币)");
                    yabi.setGmtDatetime(new Date());
                    yabi.setOrderNumber(orders.getOrderNumber());
                    flowDetailService.insert(yabi);



                    account.setYaBi(new BigDecimal(0));
                }
            }
            title="订单支付(支付宝支付)";
            FlowDetail zfb=new FlowDetail();
            zfb.setMuserId(orders.getMuserId());
            zfb.setFlowType(FlowTypeEnum.ORDER.getType());
            zfb.setMoney(orders.getCashPayPrice().multiply(new BigDecimal("-1")));
            zfb.setPayType(payWay);
            zfb.setStatus(1);
            zfb.setTitle(title);
            zfb.setGmtDatetime(new Date());
            zfb.setOrderNumber(orders.getOrderNumber());
            flowDetailService.insert(zfb);

            //*******************返现记录***********************//
            insertFlowDetail(muser.getId(),orderId,totalReurnRate,totalReturnRatey,true);

        }else if(PayTypeEnum.WEIXIN.getType()==payWay){
            if(muser.getMemberType()==1 && muser.getNums()<=10){
                account.setUnavailableDuobi(unavailableDuobi.add(new BigDecimal(totalReurnRate)));
            }else  if(muser.getMemberType()==2){
                account.setUnavailableDuobi(unavailableDuobi.add(new BigDecimal(totalReurnRate)));
                account.setUnavailableYabi(unavailableYabi.add(new BigDecimal(totalReturnRatey)));
            }
            account.setTotalMoney(account.getTotalMoney().add(totalMoney));
            if(orders.getAllowPayType()==1){//如果支持哆币支付 账号余额小于应支付金额的话先扣除余额
//                if(account.getDuoBi().compareTo(orders.getTotalPrice())<0 && account.getDuoBi().compareTo(new BigDecimal(0))>0){
//                    //*********流水记录*********//
//                    FlowDetail duobi=new FlowDetail();
//                    duobi.setMuserId(orders.getMuserId());
//                    duobi.setFlowType(FlowTypeEnum.ORDER.getType());
//                    duobi.setMoney(account.getDuoBi().multiply(new BigDecimal("-1")));
//                    duobi.setPayType(PayTypeEnum.DUOBI.getType());
//                    duobi.setStatus(1);
//                    duobi.setTitle("订单支付(哆币抵消金额)"+account.getDuoBi());
//                    duobi.setGmtDatetime(new Date());
//                    duobi.setOrderNumber(orders.getOrderNumber());
//                    flowDetailService.insert(duobi);
//
//
//                    account.setDuoBi(new BigDecimal(0));
//                }
            }else if(orders.getAllowPayType()==2){//如果支持雅币支付 账号余额小于应支付金额的话先扣除余额
                if(account.getYaBi().compareTo(orders.getTotalPrice())<0 && account.getYaBi().compareTo(new BigDecimal(0))>0){
                    //*********流水记录*********//
                    FlowDetail yabi=new FlowDetail();
                    yabi.setMuserId(orders.getMuserId());
                    yabi.setFlowType(FlowTypeEnum.ORDER.getType());
                    yabi.setMoney(account.getYaBi().multiply(new BigDecimal("-1")));
                    yabi.setPayType(PayTypeEnum.YABI.getType());
                    yabi.setStatus(1);
                    yabi.setTitle("订单支付(雅币抵消金额)"+account.getYaBi());
                    yabi.setGmtDatetime(new Date());
                    yabi.setOrderNumber(orders.getOrderNumber());
                    flowDetailService.insert(yabi);

                    account.setYaBi(new BigDecimal(0));
                }
            }
            title="订单支付(微信支付)";
            FlowDetail zfb=new FlowDetail();
            zfb.setMuserId(orders.getMuserId());
            zfb.setFlowType(FlowTypeEnum.ORDER.getType());
            zfb.setMoney(orders.getCashPayPrice().multiply(new BigDecimal("-1")));
            zfb.setPayType(payWay);
            zfb.setStatus(1);
            zfb.setTitle(title);
            zfb.setGmtDatetime(new Date());
            zfb.setOrderNumber(orders.getOrderNumber());
            flowDetailService.insert(zfb);

            //*******************返现记录***********************//
            insertFlowDetail(muser.getId(),orderId,totalReurnRate,totalReturnRatey,true);
        }
        accountMapper.updateById(account);
        return json;
    }


    /**
     * 购买返现记录
     * @param muserId 会员id
     * @param orderId  订单id
     * @param totalReurnRate 哆币总返现金额
     * @param totalReturnRatey 雅币总返现金额
     *@param insertOrUpdate   true插入 false 更新
     */

    public void insertFlowDetail(Long muserId,Long orderId,String totalReurnRate ,String totalReturnRatey,boolean insertOrUpdate){
        Muser muser=muserMapper.selectById(muserId);
        Orders orders=ordersMapper.selectById(orderId);
        //如果体验会员体验次数超过十次  不在返现
        if(muser.getMemberType()==1 && muser.getNums()>10){
            return;
        }
        if(insertOrUpdate){
            FlowDetail duoBi=new FlowDetail();
            duoBi.setOrderNumber(orders.getOrderNumber());
            duoBi.setMoney(new BigDecimal(totalReurnRate));
            duoBi.setFlowType(FlowTypeEnum.CASHBACKDUOBI.getType());
            duoBi.setMuserId(orders.getMuserId());
            duoBi.setTitle("购买返现(哆币)");
            duoBi.setStatus(5);
            duoBi.setGmtDatetime(new Date());
            flowDetailService.insert(duoBi);
            if(muser.getMemberType()==2){
                FlowDetail yaBi=new FlowDetail();
                yaBi.setOrderNumber(orders.getOrderNumber());
                yaBi.setMoney(new BigDecimal(totalReturnRatey));
                yaBi.setFlowType(FlowTypeEnum.CASHBACKYABI.getType());
                yaBi.setMuserId(orders.getMuserId());
                yaBi.setTitle("购买返现(雅币)");
                yaBi.setStatus(5);
                yaBi.setGmtDatetime(new Date());
                flowDetailService.insert(yaBi);
            }
        }else {
            EntityWrapper<FlowDetail> ew=new EntityWrapper<>();
            ew.eq("order_number",orders.getOrderNumber());
            ew.eq("status",5);
            List<FlowDetail> fdList=flowDetailService.selectList(ew);
            if(!fdList.isEmpty()){
                for (FlowDetail fd:fdList) {
                    fd.setStatus(4);
                }
                flowDetailService.updateBatchById(fdList);
            }
        }




    }

    /**
     * 购买返现
     * @param orderId
     * @return
     */
    @Override
    public JSONObject cashback(Long orderId) {
        JSONObject json=new JSONObject();
        Orders orders=ordersMapper.selectById(orderId);
        Muser muser=muserMapper.selectById(orders.getMuserId());
        if(muser.getMemberType()==1 ){
            if(muser.getNums()>10){
                json.put("message","您体验次数已满10次，不升彩虹会员将不再享有购买返现权限");
                json.put("code","200");
                return json;
            }
        }
        //获取订单返现哆币总额和雅币总额
        JSONObject jsonObject=orderGoodsService.findCashBackYbAndDuoBi(orderId,orders.getMuserId());
        if("500".equals(jsonObject.getString("code"))){
            json.put("code","500");
            json.put("message",jsonObject.get("message"));
            return json;
        }
        String totalReurnRate=jsonObject.getString("totalReurnRate");
        String totalReturnRatey=jsonObject.getString("totalReturnRatey");
        //更新账户余额
        Account userAccount=new Account();
        userAccount.setMuserId(orders.getMuserId());
        Account account=accountMapper.selectOne(userAccount);
        //更新哆币雅币余额
        account.setDuoBi(account.getDuoBi().add(new BigDecimal(totalReurnRate)));
//        if(muser.getMemberType()==2){
            account.setYaBi(account.getYaBi().add(new BigDecimal(totalReturnRatey)));
//        }
        //更新返现哆币雅币总余额
        account.setRebateDuobi(account.getRebateDuobi().add(new BigDecimal(totalReurnRate)));
//        if(muser.getMemberType()==2){
            account.setRebateYabi(account.getRebateYabi().add(new BigDecimal(totalReturnRatey)));
//        }
        //更新不可用哆币雅币总余额
        account.setUnavailableDuobi(account.getUnavailableDuobi().subtract(new BigDecimal(totalReurnRate)));
//        if(muser.getMemberType()==2){
            account.setUnavailableYabi(account.getUnavailableYabi().subtract(new BigDecimal(totalReturnRatey)));
//        }
        accountMapper.updateById(account);
        //根据消费总额更新会员等级
        BigDecimal totalMoney=account.getTotalMoney();//消费累计总额
        Integer level=muserService.getMuserLevel(totalMoney);
        if(level>muser.getMemberLevel()){
            muser.setMemberLevel(level);
            muserMapper.updateById(muser);

            /******* 会员等级提升成功提示消息******/
            Message msg=messageService.selectTemplateMsgByMsgType(4);
            if(null!=msg){
                String title=msg.getTitle();
                String content=msg.getContent()
                        .replace("#level#","VIP"+level.toString());
                MsgUser msgUser=new MsgUser();
                msgUser.setMuserId(muser.getId());
                msgUser.setTitle(title);
                //恭喜你的会员等级提升到【#level】！！
                msgUser.setMsgContent(content);
                msgUserService.insert(msgUser);
            }

            /******* 会员等级提升成功提示消息******/
            }



        json.put("code","200");
        /**************************流水记录**************************/
        insertFlowDetail(muser.getId(),orderId,totalReurnRate,totalReturnRatey,false);
        return json;
    }

    /**
     * 减库存
     * @param orderId
     * @return
     */
    @Override
    public JSONObject updateInventory(Long orderId) {
        JSONObject jsonObject=new JSONObject();
        List<OrderGoods> orderGoodses=orderGoodsMapper.selectOrderGoodsByOrderId(orderId);
       String skus="";
        int i=0,y=orderGoodses.size();
        for(;i<y;i++){
            OrderGoods orderGoods=orderGoodses.get(i);
            Long skuId=orderGoods.getSkuId();
            skus+=skuId+",";
        }
        if(!"".equals(skus)){
            skus=skus.substring(0,skus.length()-1);
        }
        EntityWrapper<Sku> ew=new EntityWrapper<>();
        ew.where("find_in_set(sku.id,'"+skus+"') >0","sku.id");
        List<Sku> skuList=skuService.selectList(ew);
        for(i=0;i<y;i++){
            OrderGoods orderGoods=orderGoodses.get(i);
            for (int m=0,n=skuList.size();m<n;m++){
                Sku sku=skuList.get(m);
                if(orderGoods.getSkuId().compareTo(sku.getId())==0){
                    Integer nums=sku.getInventory()-orderGoods.getSkuCount();
                    if(nums<0){
                        jsonObject.put("code","500");
                        jsonObject.put("message","库存不足");
                        return jsonObject;
                    }else {
                        sku.setInventory(nums);
                        break;
                    }

                }
            }
        }
        Orders order=orderService.selectById(orderId);
        if(order.getOrderType()==2){
            //试用众测订单减试用数量
            for(OrderGoods e:orderGoodses){
                EntityWrapper<ExperienceGoods> ewg=new EntityWrapper<>();
                ewg.eq("goods_id",e.getGoodsId());
                ExperienceGoods eg=experienceGoodsService.selectOne(ewg);
                if(null!=eg){
                    Integer nums=eg.getNum()-e.getSkuCount();
                    if(nums<0){
                        jsonObject.put("code","500");
                        jsonObject.put("message","抢完了");
                        return jsonObject;
                    }else{
                        if(nums==0){
                            eg.setStatus(2);
                        }
                        eg.setNum(nums);
                        experienceGoodsService.updateById(eg);
                    }
                }
            }
        }else if(order.getOrderType()==3){
            //今日特卖订单减抢购数量
            for(OrderGoods e:orderGoodses){
                EntityWrapper<PanicBuyingGoods> ewg=new EntityWrapper<>();
                ewg.eq("goods_id",e.getGoodsId());
                PanicBuyingGoods pbg=panicBuyingGoodsService.selectOne(ewg);
                if(null!=pbg){
                    Integer nums=pbg.getNum()-e.getSkuCount();
                    if(nums<0){
                        jsonObject.put("code","500");
                        jsonObject.put("message","抢完了");
                        return jsonObject;
                    }else{
                        if(nums==0){
                            pbg.setStatus(2);
                        }
                        pbg.setNum(nums);
                        panicBuyingGoodsService.updateById(pbg);
                    }
                }
            }
        }
        skuService.updateBatchById(skuList);
        jsonObject.put("code","200");
        return jsonObject;
    }

    @Override
    public void orderTask() {

        EntityWrapper<Orders> ew=new EntityWrapper<>();
        ew.eq("order_status", OrderStatusEnum.DELIVERING.getType());
        Long time=new Date().getTime()-7*24*60*60*1000;
        Date date=null;
        try {
            date=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(time));
        } catch (ParseException e) {
            e.printStackTrace();
        }
        ew.le(true,"upt_datetime",date);
        List<Orders> ordersList=ordersMapper.selectList(ew);
        if(!ordersList.isEmpty()){
            for (Orders order:ordersList  ) {
                order.setOrderStatus(OrderStatusEnum.PENDING_EVALUATION.getType());
                order.setUptDatetime(new Date());
                order.setCompleteDatetime(new Date());
            }
            orderService.updateBatchById(ordersList);
            //确认收货后的一些返利操作
            for(int i=0,y=ordersList.size();i<y;i++){
                Orders orders=ordersList.get(i);
                JSONObject jsonObject=orderService.confirmReceiptOrder(orders.getMuserId(),orders.getId());
            }

        }
    }

    /**
     * 确认收货
     * @param userId
     * @param orderId
     * @return
     */
    @Override
    public JSONObject confirmReceiptOrder(Long userId, Long orderId) {
        JSONObject json=new JSONObject();
        //购买返现
        JSONObject jsonCashBack = ordersService.cashback(orderId);
        if ("500".equals(String.valueOf(jsonCashBack.get("code")))) {
          return jsonCashBack;
        }
        // 获取购买人推荐人关系链，如果关系链上面有一个或多个推荐人为百夫长，则第一个百夫长获利
        Muser recomendMuser = muserService.findFirstRecomendUser(userId, UserTypeEnum.CENTURION.getType());
        if (recomendMuser != null) {
            JSONObject jsonRecomend = accountService.updateRecomendUserAccount(recomendMuser.getId(), orderId);
            if ("500".equals(jsonRecomend.getString("code"))) {
                return jsonRecomend;
            }
        }
        // 获取购买人推荐人关系链，如果关系链上面有一个或多个推荐人为千夫长，则第一个千夫长获利
        Muser chiefCommander = muserService.findFirstRecomendUser(userId, UserTypeEnum.ChIEFCOMMANDER.getType());
        if (chiefCommander != null) {
            JSONObject jsonChief = accountService.updateRecomendUserAccount(chiefCommander.getId(), orderId);
            if ("500".equals(jsonChief.getString("code"))) {
                return jsonChief;
            }
        }
        // 获取购买人推荐人关系链，如果关系链上面有一个或多个推荐人为加盟商，则第一个加盟商获利
        Muser franchisee = muserService.findFirstRecomendUser(userId, UserTypeEnum.FRANCHISEE.getType());
        if (franchisee != null) {
            JSONObject jsonChief = accountService.updateRecomendUserAccount(franchisee.getId(), orderId);
            if ("500".equals(jsonChief.getString("code"))) {
                return jsonChief;
            }
        }
        json.put("code","200");
        return json;
    }
    @Override
    public List<Orders> selectOrderListWithCondition(Map condition) {
        return ordersMapper.selectOrderListWithCondition(condition);
    }

    /**
     * 微信退款
     * @param outTradeNo  商户订单号
     * @param refund_fee  退款金额
     * @param refund_fee1 退款金额
     * @param path  证书路径
     * @return
     */
    @Override
    public Map<String, String> wxRefund(String outTradeNo, String refund_fee, String refund_fee1, String path) {
        Map<String, String>  refundMap= RefundUtil.wechatRefund(outTradeNo,refund_fee,refund_fee,path);
        return refundMap;
    }

    /**
     * 支付宝退款
     * @param outTradeNo 商户订单号
     * @param s 空字符串
     * @param v 退款金额
     * @return
     */
    @Override
    public String alipayRefund(String outTradeNo, String s, double v) {
        String strResponse=  AlipayRefundUtil.alipayRefundRequest(outTradeNo,"",v);
        return strResponse;
    }

    @Override
    public List<Map> selectBuyTogehterList(Map map) {
        return ordersMapper.selectBuyTogehterList(map);
    }

    @Override
    public Integer selectBuyTogehterListSize(Map map) {

        return ordersMapper.selectBuyTogehterListSize(map);
    }

    @Override
    public Integer selectOrderListSize(Map condition) {
        return ordersMapper.selectOrderListSize(condition);
    }


    public static void main(String str[]){
        Long time=new Date().getTime()-7*24*60*60*1000;
        Date date=null;
        try {
            date=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(time));
        } catch (ParseException e) {
            e.printStackTrace();
        }
        System.out.print(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(date));
    }


}
